package cc.comac.mom.datahandlers.entity.config;

import cc.comac.mom.bean.config.EquipConnectConfigParamBean;
import cc.comac.mom.dao.entity.config.EquipConnectConfigDao;
import cc.comac.mom.dao.entity.config.EquipConnectConfigGroupDetailDao;
import cc.comac.mom.entity.config.EquipConnectConfigEntity;
import cc.comac.mom.entity.config.EquipConnectConfigGroupDetailEntity;
import cc.comac.mom.entity.config.EquipConnectConfigGroupEntity;
import cc.comac.mom.util.BaseEntityDataUtil;
import cc.comac.mom.util.ResultBean;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
@Transactional
public class EquipConnectConfigGroupDetailDataHandler extends ServiceImpl<EquipConnectConfigGroupDetailDao, EquipConnectConfigGroupDetailEntity> {
	@Autowired
	private EquipConnectConfigGroupDetailDao equipConnectConfigGroupDetailDao;
	@Autowired
	private BaseEntityDataUtil baseEntityDataUtil;

	public ResultBean saveEquipConnectConfigGroupDetail(List<EquipConnectConfigGroupDetailEntity> list) {
		ResultBean resultBean = new ResultBean(true);
		for(EquipConnectConfigGroupDetailEntity e:list){
			baseEntityDataUtil.setBaseEntityData(e);
		}
		Boolean insert = this.saveBatch(list);
		if (!insert) {
			throw new RuntimeException("新增失败");
		}
		resultBean.setObject(list);
		return resultBean;
	}
	public ResultBean updateEquipConnectConfigGroupDetail(List<EquipConnectConfigGroupDetailEntity> list) {
		ResultBean resultBean = new ResultBean(true);

		for(EquipConnectConfigGroupDetailEntity e:list){
			baseEntityDataUtil.updateBaseEntityData(e);
		}
        this.updateBatchById(list);
		return resultBean;
	}

	public ResultBean delete(List<Long> groupId) {
		ResultBean resultBean = new ResultBean(true);
		if (groupId == null) {
			throw new RuntimeException("数据为空");
		}
		QueryWrapper<EquipConnectConfigGroupDetailEntity> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("row_status", 1);
		queryWrapper.in("group_id",groupId);
		List<EquipConnectConfigGroupDetailEntity> list = equipConnectConfigGroupDetailDao.selectList(queryWrapper);
		if (list != null) {
			for(EquipConnectConfigGroupDetailEntity e:list){
				e.setRowStatus(0);
				baseEntityDataUtil.updateBaseEntityData(e);

			}
			this.updateBatchById(list);
		}
		return resultBean;
	}


}
